﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using BLL;
using Model;
public partial class partylist : System.Web.UI.Page
{
    private int PageIndex { get { return (int)ViewState["index"]; } set { ViewState["index"] = value; } }
    protected void Page_Load(object sender, EventArgs e)
    {
        string type = Request.QueryString["id"];
        if (!IsPostBack)
        {
            PageIndex = 1;
            if (string.IsNullOrWhiteSpace(type))
            {
                LoadArticle();
            }
            else
            {
                LoadArticle(int.Parse(type));
            }
        }
    }

    private void LoadArticle()
    {
        StringBuilder sb = new StringBuilder();
        BllPartyinfor bll = new BllPartyinfor();
        webPager.RecordCount = bll.GetCount(c => true);

        var list = bll.GetList(c => true, true, c => c.time, PageIndex, webPager.PageSize);
        foreach (var item in list)
        {
            sb.Append(string.Format(@"<li>·<a href='partyc.aspx?id={2}' target='_blank' title='{0}'> <span>{0}</span><span class='right'>{1}</span></a></li>", item.name, item.time, item.id));
        }
        ltlList.Text = sb.ToString();
    }
    private void LoadArticle(int type)
    {
        StringBuilder sb = new StringBuilder();
        BllPartyinfor bll = new BllPartyinfor();
        webPager.RecordCount = bll.GetCount(c => c.type == type);

        var list = bll.GetList(c => c.type == type, true, c => c.time, PageIndex, webPager.PageSize);
        foreach (var item in list)
        {
            sb.Append(string.Format(@" <li>·<a href='partyc.aspx?id={2}' target='_blank' title='{0}'> <span>{0}</span><span class='right'>{1}</span></a></li>", item.name, item.time, item.id));
        }
        ltlList.Text = sb.ToString();
    }
    protected void webPager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        PageIndex = e.NewPageIndex;
        string type = Request.QueryString["type"];
        if (string.IsNullOrWhiteSpace(type))
        {
            LoadArticle();
        }
        else
        {
            LoadArticle(int.Parse(type));
        }
    }
}